package com.lwz.mediator.computer;

import com.lwz.mediator.Colleague;
import com.lwz.mediator.Mediator;

public class MainBoard implements Mediator {
	
	private CPU cpu;
	
	private CDDriver cdDriver;
	
	private SoundCard soundCard;
	
	private VideoCard videoCard;
	
	

	public void setCpu(CPU cpu) {
		this.cpu = cpu;
	}



	public void setCdDriver(CDDriver cdDriver) {
		this.cdDriver = cdDriver;
	}



	public void setSoundCard(SoundCard soundCard) {
		this.soundCard = soundCard;
	}



	public void setVideoCard(VideoCard videoCard) {
		this.videoCard = videoCard;
	}



	@Override
	public void change(Colleague colleague) {
		if(colleague == cdDriver){
			operateCDDriver(cdDriver);
		}else if(colleague == cpu){
			operateCPU(cpu);
		}
	}
	/**
	 * 操作 光驱
	 */
	public void operateCDDriver(CDDriver cdDriver){
		//获取光驱数据
		String data = cdDriver.getData();
		this.cpu.splitData(data);
	}
	/**
	 * 操作 cpu
	 */
    public void operateCPU(CPU cpu){
    	//获取cpu处理厚的数据
    	      String soundData = cpu.getSoundData();
    	      String videoData = cpu.getVideoData();
    	      //给声卡和显卡使用
      this.videoCard.opeVideo(videoData);
      this.soundCard.opeSound(soundData);
	}
}
